---
title: PdfClientService
summary: API reference for PdfClientService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-17
library: PdfAPI.Core
reference_type: package
---

# PdfClientService

`PdfClientService` is the only behavior-bearing type in the library — a static, stateless iTextSharp-backed facade providing PDF inspection (`IsPdf`, `Version`, `GetPageCount`, `HasFormFields`), transformation (`Flatten`, `ExtractPages`/`ExtractPageRanges`), and guard (`ValidatePdf`) operations. It is consumed directly by `PdfAPI\Services\PdfService.cs`, re-exposed as instance methods by `PdfAPI.Client\PdfClient.cs`, and executes entirely in the caller's process with no network or database access.

## Purpose
- Provides low-level, stateless PDF inspection and transformation primitives backed by iTextSharp 5.5.11.
- Enforces the input-validation guard used throughout the platform before any PDF byte array is trusted. ([BR-01](../../business-rules.md#br-01-pdf-signature-validation), [BR-03](../../business-rules.md#br-03-invalid-pdf-input-aborts-with-pdfexception))
- Because all members are static, consumers cannot substitute or mock this service directly; `PdfAPI\Services\PdfService.cs` wraps it in instance methods to allow switching to alternative implementations.

## Context
- Namespace: `PdfAPI.Core`
- Assembly/package: `PdfAPI.Core`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| HasFormFields(byte[]) | `static bool HasFormFields(byte[] file)` | Detects whether the PDF contains an AcroForm with fillable form fields. ([BR-10](../../business-rules.md#br-10-form-field-detection-requires-acroform)) |
| Flatten(byte[]) | `static byte[] Flatten(byte[] file)` | Flattens AcroForm form fields into static content, returning the original bytes unchanged when no AcroForm is present. ([BR-11](../../business-rules.md#br-11-flattening-only-applies-with-acroform)) |
| IsPdf(byte[]) | `static bool IsPdf(byte[] file)` | Tests whether the byte array begins with the `%PDF-` signature. ([BR-01](../../business-rules.md#br-01-pdf-signature-validation), [BR-02](../../business-rules.md#br-02-null-bytes-are-never-a-pdf)) |
| Version(byte[]) | `static string Version(byte[] file)` | Reads the PDF version declared in the file header. ([BR-08](../../business-rules.md#br-08-pdf-version-extraction)) |
| GetPageCount(byte[]) | `static int GetPageCount(byte[] file)` | Counts pages by scanning for page markers. ([BR-09](../../business-rules.md#br-09-page-count-via-marker-scan)) |
| ExtractPages(DocumentRange) | `static PdfResult ExtractPages(DocumentRange documentRange)` | Opens the source document and delegates to `ExtractPageRanges` to produce a new PDF containing the selected pages. See [Extract pages](../../operations/op-08-extract-pages.md). |
| ExtractPageRanges(PdfReader, DocumentRange) | `static PdfResult ExtractPageRanges(iTextSharp.text.pdf.PdfReader sourceDocReader, DocumentRange documentRange)` | Copies the selected page ranges from an already-open `PdfReader` into a new PDF via `PdfCopy`. See [Extract pages](../../operations/op-08-extract-pages.md). ([BR-12](../../business-rules.md#br-12-out-of-range-page-ranges-are-skipped), [BR-13](../../business-rules.md#br-13-page-boundaries-are-clamped-to-page-count), [BR-14](../../business-rules.md#br-14-original-range-copies-the-whole-document), [BR-15](../../business-rules.md#br-15-open-ended-stop-page-means-through-last-page), [BR-16](../../business-rules.md#br-16-descending-range-reverses-page-order), [BR-17](../../business-rules.md#br-17-successful-extraction-returns-a-new-succeeded-result), [BR-18](../../business-rules.md#br-18-extraction-result-records-processor-and-page-expression)) |
| ValidatePdf(byte[], string) | `static void ValidatePdf(byte[] file, string fileName = null)` | Throws `PdfException` when `file` is not a valid PDF. See [Validate PDF bytes](../../operations/op-01-validate-pdf-bytes.md). ([BR-01](../../business-rules.md#br-01-pdf-signature-validation), [BR-02](../../business-rules.md#br-02-null-bytes-are-never-a-pdf), [BR-03](../../business-rules.md#br-03-invalid-pdf-input-aborts-with-pdfexception)) |
| ValidatePdf(Document, PdfOptions) | `static void ValidatePdf(Document document, PdfOptions options)` | Loads a document, optionally deletes its source file, and validates the resulting bytes. See [Validate a document](../../operations/op-02-validate-a-document.md). ([BR-04](../../business-rules.md#br-04-document-validation-requires-a-non-null-document), [BR-05](../../business-rules.md#br-05-document-load-requires-in-memory-or-on-disk-bytes), [BR-06](../../business-rules.md#br-06-failed-document-load-aborts-validation), [BR-07](../../business-rules.md#br-07-input-file-cleanup-after-load)) |

## Behavioral notes
- `ExtractPageRanges` exposes `iTextSharp.text.pdf.PdfReader` in its public signature, making iTextSharp a compile-time-visible dependency for any package consumer that calls this overload directly.
- `ValidatePdf(Document, PdfOptions)` deletes the on-disk source file (step 4) before running the PDF signature check (step 5), so a document that fails validation has already lost its on-disk copy. ([BR-07](../../business-rules.md#br-07-input-file-cleanup-after-load))

## Constraints and usage notes
- All members are static; there is no instance to construct, inject, or mock. Callers needing substitutability must wrap this type themselves.

## Related documentation
- [Index](../../index.md)
- [Overview](../../overview.md)
- [Architecture](../../architecture.md)
- [Dependencies](../../dependencies.md)
- [Operations and processes](../../operations-processes.md)
- [Business rules](../../business-rules.md)
- [Security and authorization](../../security-authorization.md)
- [API reference](../index.md)

## Sources
- `PdfAPI.Core\Services\PdfClientService.cs`
